package org.cying.main.service;

import cn.hutool.core.date.DateUtil;
import org.cying.main.dao.CreateUnsign;
import org.cying.main.dao.DeleteUnsign;
import org.cying.main.dao.QueryUnsign;
import org.cying.main.domain.Unsign;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 签到映射接口控制类
 * @author Cying
 */
@Service
public class UnSignService {

    @Resource
    private QueryUnsign query;
    
    @Resource
    private CreateUnsign create;

    @Resource
    private DeleteUnsign delete;

    public boolean delete(String department, String group) {
        Map<String, String> map = new HashMap<>();
        map.put("department", department);
        map.put("group", group);
        return delete.delete(map) > 0;
    }

    public List<Unsign> getUnSigns(Long sid, String name, String exp, String dept, String group) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("sid", sid);
        map.put("name", name);
        map.put("exp", exp);
        map.put("dept", dept);
        map.put("group", group);
        return query.getUnSigns(map);
    }
    
    public void insert(Long sid, String info) {
        Map<String, Object> map = new HashMap<>();
        map.put("sid", sid);
        map.put("date", DateUtil.today());
        map.put("time", info);
        map.put("week", DateUtil.thisDayOfWeek() - 1);
        create.insert(map);
    }

}
